package cn.wolfcode.wolf2w.persistence;

import cn.wolfcode.wolf2w.cache.service.IVisitorRedisService;
import cn.wolfcode.wolf2w.cache.vo.VisitorVo;
import cn.wolfcode.wolf2w.service.IVisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis数据库持久化任务
 */

//@Component //（扫描定时器  持久化）
public class VisitorRedisDataPersistenceJob {
    @Autowired
    private IVisitorRedisService visitorRedisService;
    @Autowired
    private IVisitorService visitorService;

    @Scheduled(cron = "0/10 * * * * *") // 设置更新周期时间
    public void persistence(){
        System.out.println("vo持久化----------------------------start");
        // 查询所有redis中的所有vo对象，使用前缀+ * 的命令查询操作
        List<VisitorVo> voList = visitorRedisService.queryVisitorVoBypatten("*");

        // 遍历vo对象，将数据加入mongodbdb数据库中
        for (VisitorVo vo : voList) {

            visitorService.updateVisitorVo(vo);
        }
        System.out.println("vo持久化----------------------------end");
    }
}
